
*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table C5
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************


cd "~/Dropbox/ReclassificationRisk/data_stata"
use database_individual_level.dta, replace 


**************************************************************************************************
** BEGINING OF USIC ESTIMATES
** TWO STEP REGRESSION USING THIS SAMPLE (ROBUSTNESS ON LEAVING THE SAMPLE) **
**************************************************************************************************
tsset mbr_sys_id year
egen stderrorscluster = group(customer_number year)
gen SEX = (gdr_cd=="F")
gen industry = substr(sic_cd,1,1)
tab industry, gen(industy_dummy)
**************************************************************************************************
local conditions "lagged_code_hypertension lagged_code_heartfailure lagged_chronic_ami laggeed_code_respfailure  lagged_code_brainhemorr lagged_chronic_cancer lagged_chronic_diabetes lagged_code_asthma" 
mkspline reg16 1 reg17 = mean_pred_riskscore_rp 
*if year==2015 /*making the spline on the delta for 2015, cross section estimate */
*gen reg1 =  mean_pred_riskscore_rp 
gen reg2 = laggedscore
gen reg3 = age 
gen reg4 = SEX
gen reg5 = industy_dummy1 
gen reg6 = industy_dummy2
gen reg7 = industy_dummy3
gen reg8 = industy_dummy4 
gen reg9 = industy_dummy5
gen reg10 = industy_dummy6
gen reg11 = industy_dummy7
gen reg12 = industy_dummy8
gen reg13 = industy_dummy9
gen reg14 = industy_dummy10
gen reg15 = numpeople
probit exit_new reg* if year==2014, cluster(stderrorscluster) noconstant
forvalues i=2/17 {
scalar coeffprobit`i' = _b[reg`i']
}
*probit exit_new laggedscore mean_pred_riskscore_rp age SEX industy_dummy* numpeople if year==2014, cluster(stderrorscluster) noconstant
local n_probit = e(N)
matrix V = e(V)* `n_probit'
*ivprobit exit_new (laggedscore mean_pred_riskscore_rp = laggedscore_ORS mean_ORS_riskscore_rp) age SEX industy_dummy* numpeople if year==2014, cluster(stderrorscluster) 
margins, dydx(*)
predict linear_index, xb
gen prob_leaving = normal(linear_index)
gen prob_leaving2 = prob_leaving^2
gen prob_leaving3 = prob_leaving^3
gen prob_leaving4 = prob_leaving^4
gen prob_leaving5 = prob_leaving^5
gen prob_leaving6 = prob_leaving^6 
tsset mbr_sys_id year
***** *****

*reghdfe mean_premium yeardum* (mean_pred_riskscore_rp = mean_ORS_riskscore_rp), absorb(mbr_sys_id) vce(cluster customer_number year)
reghdfe mean_premium mean_pred_riskscore_rp prob_leaving* yeardum* , absorb(mbr_sys_id) vce(cluster customer_number year)
gen sample = e(sample)


**************************************************************************************************
**** EFFECTS FOR DIFFERENT PERIODS
*********************************************************************************
set more off
reghdfe mean_premium mean_pred_riskscore_rp  prob_leaving* yeardum* if year<2015, absorb(mbr_sys_id) cluster(customer_number year)
eststo mod1
  reghdfe  mean_premium  mean_pred_riskscore_rp prob_leaving*  yeardum* marketdum* if year<2015 & sample==1 , noabsorb vce(cluster customer_number year)
eststo mod2
reghdfe mean_premium  mean_pred_riskscore_rp prob_leaving* yeardum* if year>2013, absorb(mbr_sys_id) cluster(customer_number year)
eststo mod3
  reghdfe  mean_premium mean_pred_riskscore_rp prob_leaving*  yeardum* marketdum* if year>2013 & sample==1 , noabsorb vce(cluster customer_number year)
eststo mod4

/*
****************************************************************************************************************** fragment
*********TABLE 
esttab mod1 mod2 mod3 mod4 using TableA_FirmLevel_DifferentPeriods.tex , replace label    nonotes nonumbers stats(N, fmt(%12.0fc)) compress cells(b(star fmt(%12.0fc %12.0fc %12.4fc ) label(" ")) se(fmt( %12.0fc %12.4fc) label(" ") par) ) collabels(none) nogaps  ///
		title(ACG Score and Claims Pass-through to Premiums. Two Lags Specification) mtitles("I" "II" "III" "IV") ///
		star(* 0.10 ** 0.05 *** 0.01)  ///
		keep( mean_pred_riskscore_rp  ) ///
		prefoot( \hline "Dep. Var. & Premium & Premium & Premium & Premium" \\ /// 
		"Firm FE & Yes & No & Yes & No "\\ ///		
		"Market FE & No & Yes & No & Yes " \\ ///
		"Year FE & Yes & Yes & Yes & Yes" \\  \hline) 
eststo clear
*********************************************************************************************
